Skip to content

[mlir][Sol] Replace the Sol-to-Yul dialect conversion with a direct lowering - #238

Open
abinavpp wants to merge 1 commit into
mainfrom
app-sol-to-yul-direct
Open

abinavpp wants to merge 1 commit into
mainfrom
app-sol-to-yul-direct

Conversation

@abinavpp

@abinavpp abinavpp commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Lowers Sol to Yul in one walk over the contract, replacing the staged dialect conversions. The LLVM IR, debug info included, is unchanged.

Companion: NomicFoundation/solx#947

Improvements:

  • One walk, no stages. The stages existed because some lowerings read ops that a later stage converts; every yul.func is now declared up front and the contract is lowered after its bodies, so one walk suffices.
  • Helpers are generated as yul.func directly, no longer as a sol.func with sol.call/sol.return that existed only to be converted to Yul in a later stage.
  • sol.try builds its control flow and allocas directly, instead of emitting Sol ops to be lowered later, and maps its clause arguments instead of replacing them behind the rewriter's back.
  • Inline assembly bodies are cloned over the lowered operands, instead of being moved in and patched by the driver through materialization casts. The only cast left is the pointer cast to !yul.ptr (see the open question).
  • sol.ext_icall calls the external call lowering directly, instead of building a temporary sol.ext_call and lowering that.
  • Compile time. convert-sol-to-yul takes about 60% less time, but a whole compile only about 3% less, since LLVM dominates it. Each op is built once, in place, with no rewrite log or rollback.
  • No materialization casts between Sol and Yul types, so sol.conv_cast is deleted from the Sol dialect.
  • No pattern boilerplate. Each op is one lower overload over the already-lowered operands (an IRMapping), in place of the OpConversionPattern structs, the CleanedOperandsLowering template dispatch and the populate*Pats sets. Shared state (the string literal pool, the internal dispatch) is a member, no longer threaded through every pattern's constructor.
  • Better debugging, maybe? A stack trace or debugger step leads straight to an op's lowering, with no worklist, legalization or rollback in between.

Open questions

  • !yul.ptr vs !llvm.ptr. A lowered Sol stack slot is an !llvm.ptr (llvm.alloca, llvm.getelementptr), while inline assembly's yul.load/yul.store take a !yul.ptr. The lowering bridges them with an unrealized_conversion_cast at each use, which the Yul translation reads through. Either:

    • yul.alloca, yul.load and yul.store work on !llvm.ptr and !yul.ptr goes away, or
    • Yul gets its own address ops (a GEP and the like) yielding !yul.ptr.

    The first is a small change (the Yul op definitions, the translation's cast handling, and solx's pointer type) and works as is: with it, the LLVM IR is unchanged and the solx tests pass.

  • Location tracking. The lit tests barely check the locations the lowering gives its ops, so a change can move one unnoticed. How should this be tested? A lit test can pin each lowered op to its Sol op's line (-mlir-print-debuginfo with loc({{.*}}:[[@LINE+1]]:<col>)), but the relative line numbers need the CHECK lines interleaved with the input.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The central SolToYul.cpp lowering diff is missing, preventing reliable review of semantic preservation and LLVM IR/debug-info equivalence.

No open issues 🎉

What changed in this PR

Refactors MLIR’s Sol-to-Yul lowering from staged dialect conversions to a single contract walk, aiming to reduce compilation overhead while preserving generated LLVM IR and debug information.

Changes:

  • Uses direct type mapping and Yul functions for helpers and internal dispatch.
  • Removes the staged conversion driver, type converter, and sol.conv_cast operation.
  • Updates inline-assembly checks for pointer casts emitted at each use.
File Description
mlir/​test/​Conversion/​SolToYul/​inline-asm.mlir Updates pointer-cast placement expectations.
mlir/​lib/​Dialect/​Sol/​SolOps.cpp Removes the obsolete conversion-cast folder.
mlir/​lib/​Conversion/​SolToYul/​TypeConverter.cpp Deletes the materializing type converter.
mlir/​lib/​Conversion/​SolToYul/​SolToYulPass.cpp Deletes the staged conversion driver.
mlir/​lib/​Conversion/​SolToYul/​InternalDispatch.cpp Tracks Yul function targets and their IDs directly.
mlir/​lib/​Conversion/​SolToYul/​EVMUtil.cpp Adds direct type mapping and generates helpers as Yul functions.
mlir/​lib/​Conversion/​SolToYul/​CMakeLists.txt Removes deleted sources and conversion dependencies.
mlir/​include/​mlir/​Dialect/​Sol/​SolOps.td Removes the sol.conv_cast definition.
mlir/​include/​mlir/​Conversion/​SolToYul/​Util.h Adds signedness-aware 256-bit constant generation.
mlir/​include/​mlir/​Conversion/​SolToYul/​SolToYul.h Updates dispatch state and removes conversion-pattern APIs.
mlir/​include/​mlir/​Conversion/​SolToYul/​EVMUtil.h Exposes direct lowering utilities and simplifies decoding APIs.

Review effort: Balanced

@abinavpp
abinavpp force-pushed the app-sol-to-yul-direct branch from 7989305 to ab57e54 Compare November 17, 2026 22:11
@abinavpp abinavpp changed the title [mlir][Sol] Lower Sol to Yul in one walk over the contract [mlir][Sol] Replace the Sol-to-Yul dialect conversion with a direct lowering Nov 17, 2026
@abinavpp
abinavpp marked this pull request as ready for review November 17, 2026 22:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants